<template>
	<view class=" ">
		<view class="flex a-c p3 bb">
			<view class="" style="width: 150rpx;">
				<text class="f30">选择分类</text>
			</view>
			<view class="ml2" style="flex:1">
				<lb-picker :zIndex="99999" @confirm="on_navcate" :list="nav_list" :level="2" mode="multiSelector">
					<text class="f28  ">{{cata_name}}</text>
				</lb-picker>
			</view>
		</view>

		<view class="flex a-c p3 bb">
			<view class="" style="width: 150rpx;">
				<text class="f30">文章标题</text>
			</view>
			<view class="ml2" style="flex:1">
				<input type="text" v-model="find.title" class="f26" style="flex:1" placeholder="请输入标题">
			</view>
		</view>
		<view class="flex a-c p3 ">
			<view class="" style="width: 150rpx;">
				<text class="f30">文章内容</text>
			</view>

		</view>




		<view class="flex j-c a-c" @click="on_post" style="position: fixed;bottom: 460rpx;width: 750rpx;">
			<view class="flex j-c a-c  button_bg" style="width: 80%;height: 80rpx;">
				<text>确认发布</text><text v-if="article_pay_money>0">({{article_pay_money}}元)</text>
			</view>
		</view>

		<view class="flex j-c a-c" @click="on_video" style="position: fixed;bottom: 260rpx;width: 750rpx;">
			<view class="flex j-c a-c  button_bg" style="width: 80%;height: 80rpx;">
				<text>视频上传</text>
			</view>
		</view>
		<view class="flex j-c a-c" @click="on_file" style="position: fixed;bottom: 360rpx;width: 750rpx;">
			<view class="flex j-c a-c  button_bg" style="width: 80%;height: 80rpx;">
				<text>文件上传</text>
			</view>
		</view>
		<view class="flex j-c a-c" @click="on_img" style="position: fixed;bottom: 160rpx;width: 750rpx;">
			<view class="flex j-c a-c  button_bg" style="width: 80%;height: 80rpx;">
				<text>图片上传</text>
			</view>
		</view>

		<b-wei-pay v-if="is_pay" jump_type="redirectTo" jump_url="pages/banmitongcheng/order_list/order_list"
			:pay_find="pay_find" @close="pay_close" @confirm="pay_confirm">
		</b-wei-pay>

		<tabbar></tabbar>

		<uni-popup ref="popup" :mask-click="true">
			<view class="b_y" style="background-color: #fff;padding: 10rpx;height: 80vh;">
				<view class="flex j-f p1" @click="on_close_popup">
					<uni-icons type="close" color="#ccc" size="30"></uni-icons>
				</view>
				<scroll-view scroll-y="true" style="height: 70vh;padding: 10rpx;">
					<linke-ux-parser :list="content"></linke-ux-parser>
				</scroll-view>
			</view>
		</uni-popup>

	</view>
</template>

<script>
 
	export default {
		components: {

		},
		data() {
			return {
				find: {
					name: '11',
					category_id: 0,
					title: '22',
					content: '222'
				},
				cata_name: '请选择分类',
				nav_list: [],
				is_pay: false,
				pay_find: {},
				article_pay_money: 0,
				readOnly: false,
				data: [],
				content: [],

			}
		},
		watch: {

			content: {
				handler(newName) {
					//保存草稿
					if (newName.length > 0) {
						uni.setStorageSync('b_content', newName);
					}
				},
				immediate: true,
				deep: true
			}
		},
		onLoad(on) {
			this.id = 0;
			if (on.id) {
				this.id = on.id;
			}
			if (uni.getStorageSync('b_content')) {
				this.content = uni.getStorageSync('b_content')
			}
			this.Articlecategory_init();
		},
		methods: {
			async on_file() {



				const ret = await this.Bmupload.chooseFile();
				console.log("ret: " + JSON.stringify(ret));

				if (ret != 0) {
					this.Bmupload.banmi_upload({
						files: ret,
						onProgressUpdate: res => {
							// console.log("上传进度: " + JSON.stringify(res));
						}
					}).then(res => {
						console.log("全部上传成功: " + JSON.stringify(res));

					});
				}

			},
			async on_video() {
				const ret = await this.Bmupload.chooseVideo();
		
				if (ret != 0) {
					this.Bmupload.banmi_upload({
						files: ret,
						onProgressUpdate: res => {
							// console.log("上传进度: " + JSON.stringify(res));
						}
					}).then(res => {
						console.log("全部上传成功: " + JSON.stringify(res));

					});
				}

			},
			async on_img() {


				let that = this;
				//选择图片
				const ret = await this.Bmupload.chooseImage();
				
				if (ret != 0) {
					this.Bmupload.banmi_upload({
						files: ret,
						onProgressUpdate: res => {
							console.log("上传进度: " + JSON.stringify(res));
						}
					}).then(res => {
						console.log("全部上传成功: " + JSON.stringify(res));

					});
				}



			},
			PreviewContent() {

				this.$refs.popup.open('bottom')
			},
			on_close_popup() {
				this.$refs.popup.close()
			},
			//支付完成
			//支付标识 pay_code 
			pay_confirm(pay_code) {
				this.is_pay = false;
			},
			//支付关闭
			pay_close() {
				this.is_pay = false;
			},
			on_post() {
				if (!this.find.category_id) {
					uni.showToast({
						title: '请选择分类',
						icon: 'error'
					})
					return
				}
				uni.showLoading({
					title: '提交中...',
					mask: true,
				})
				this.ajax_post();
			},
			ajax_post() {
				let that = this;
				this.find.id = this.id;
				this.find.content = JSON.stringify(this.content)
				let requestParams = this.find;
				this.Http.post('/plugin.php/banmitongcheng/api/Article/edit', requestParams).then(ret => {
					uni.hideLoading()
					if (ret.status == 300) {
						this.pay_find = ret.data;
						this.is_pay = true;
						return
					}
					uni.showToast({
						title: ret.msg,
						icon: 'none'
					})
					if (ret.status == 200) {
						return
					}


				})
			},
			on_navcate(picker) {

				this.cata_name = picker.item[0];
				var index = picker.index[0];
				this.find.category_id = this.n_list[index]['id'];
				this.article_pay_money = this.n_list[index]['article_pay_money'];


			},
			Articlecategory_init() {
				let that = this;
				let requestParams = {
					page: this.article_page,
				};
				this.Http.post('/plugin.php/banmitongcheng/api/Articlecategory/lists', requestParams).then(ret => {
					if (ret.status == 200) {
						let list = ret.data.list.list.data;
						this.n_list = list;

						var name = '';
						for (var i = 0; i < list.length; i++) {
							if (i == 0) {
								name += list[i]['name']
							} else {
								name += ',' + list[i]['name'];
							}
						}
						this.nav_list = name.split(",");



					}
				})
			},
		}
	}
</script>

<style>

</style>